package com.lovely602.thread.completablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author lizhixing
 */
public class CompletableFutureDemo {

    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(2);

        CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
                    System.out.println("异步任务1执行");
                }, executor)
                .thenRunAsync(() -> {
                    System.out.println("异步任务2执行");
                }, executor);

        future.join(); // 等待异步任务完成
        executor.shutdown();
    }

}
